/**
    创建学生类，学生对象具有姓名name，学号numb成绩score属性，
    创建StudentManager学生管理类，封装添加学生addStudent，删除学生deleteStudent，
    查看所有学生showAllStudent功能。
 */
class Student {
	public name: string // 姓名
	public num: number // 学号
	public score: number //成绩

	constructor(name: string, num: number, score: number) {
		this.name = name
		this.num = num
		this.score = score
	}
	public setName(name: string): void {
		this.name = name
	}
	public getName(): string {
		return this.name
	}
}
// const stu1 = new Student('jack',1001,98)
// stu1.setName('rose')
// console.log(stu1.getName())

class StudentManager {
	private static studentList: Student[] = []
	/**
	 *  添加学生
	 */
	public addStudent(name: string, num: number, score: number):void {
		const stu:Student = new Student(name, num, score)
		StudentManager.studentList.push(stu)
        console.log('添加学生成功！')
	}
	/**
	 *  删除学生
     *  删除数组中某元素 [1,2,3,4,5]
     *   filter()
     *   splice(index,count)
     *     根据学号查找索引号  findIndex()  map find  reduce filter every some
	 */
	public deleteStudent(num: number):void {
        // 查找学号等于传入参数学号的学生在学生数组中索引号
        const index:number = StudentManager.studentList.findIndex( (stu:Student) => stu.num == num)
        if(index == -1){
            console.log('删除的学生不存在!')
            return
        }
        StudentManager.studentList.splice(index,1)
        console.log('删除学生成功！')
    }
    /**
     * 显示所有学生
     */
     public showAllStudent():void{
         StudentManager.studentList.forEach((stu:Student)=>{
             console.log(`姓名: ${stu.name} 学号: ${stu.num} 成绩: ${stu.score}`)
         })
     }
}

class StudentManagerTest{
    public static main():void{
        const studentManager:StudentManager = new StudentManager()
        // 添加三个学生
        studentManager.addStudent('jack',1001,98)
        studentManager.addStudent('rose',1002,88)
        studentManager.addStudent('tom',1001,79)

        studentManager.showAllStudent()  //显示所有学生

        studentManager.deleteStudent(1001) //删除学号为1001学生
    }
}

StudentManagerTest.main() // 入口